/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CheckInPanel.java
 *
 * Created on Jul 26, 2011, 2:47:34 PM
 */
package panels;

import conn.EMIS4Connection;
import java.awt.GridBagConstraints;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import dao.LoginDao;
import dao.LoginHistoryDao;
import dao.PersonDao;
import dao.UpdateHistoryDao;
import java.util.logging.Level;
import java.util.logging.Logger;
import obj.Login;
import obj.LoginHistory;
import obj.Person;
import obj.UpdateHistory;
import obj.Appointment;
import util.DashboardUtil;
import util.PersonRequested;

/**
 *
 * @author nknowles
 */
public class CheckInPanel extends javax.swing.JPanel {

    private final int MAX_TRIES = 5;
    private boolean matches;
    private EMIS4Connection conn;
    private PersonRequested pr = PersonRequested.getInstance();
    private GridBagConstraints gridBagConstraints;
    private int numTries;
    private InetAddress ip;
    private List<Login> loginList;
    private Login login;
    private LoginDao loginDAO;
    private LoginHistory loginHistory;
    private LoginHistoryDao loginHistoryDAO;
    private Person person;
    private PersonDao personDAO;
    private String username, pass, firstName;
    private UpdateHistory history;
    private UpdateHistoryDao historyDAO;
    private Appointment appointment;

    /** Creates new form CheckInPanel */
    public CheckInPanel() {
        initComponents();
        conn = EMIS4Connection.getInstance();
        loginDAO = new LoginDao();
        login = new Login();
        loginHistory = new LoginHistory();
        loginHistoryDAO = new LoginHistoryDao();
        person = new Person();
        personDAO = new PersonDao();
        history = new UpdateHistory();
        historyDAO = new UpdateHistoryDao();

        try {
            ip = InetAddress.getLocalHost();
        } catch (UnknownHostException ex) {
            Logger.getLogger(LoginPanel.class.getName()).log(Level.SEVERE, null, ex);
        }

        // search for patient if pr is empty
        if (pr.getPerson() == null) {
            DashboardUtil.searchForPatient();
        }

        // fill information
        fillInformation();

//    numTries = 0;
//    usernameTextField.setInputVerifier(new verification.TextFieldVerifier(this, usernameField, "Username cannot be blank", 6, 25));
//    passField.setInputVerifier(new verification.PasswordFieldVerifier(this, passField, "Password cannot be blank", 6, 25));
//    submitButton.setEnabled(false);
    }

    private void fillInformation() {
        Person patient = pr.getPerson();

        patientNameField.setText(patient.getLastName() + ", " + patient.getFirstName());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        checkinButton = new javax.swing.JButton();
        checkinCheckBox = new javax.swing.JCheckBox();
        patientNameField = new javax.swing.JLabel();

        setLayout(new java.awt.GridBagLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel1.setText("Member Check In");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(20, 15, 10, 15);
        add(jLabel1, gridBagConstraints);

        jLabel2.setText("Patient:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 25, 0, 0);
        add(jLabel2, gridBagConstraints);

        checkinButton.setText("Check In");
        checkinButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkinButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(15, 80, 15, 15);
        add(checkinButton, gridBagConstraints);

        checkinCheckBox.setText("Checked In");
        checkinCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkinCheckBoxActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
        add(checkinCheckBox, gridBagConstraints);

        patientNameField.setText("Last, First");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
        gridBagConstraints.insets = new java.awt.Insets(6, 5, 0, 0);
        add(patientNameField, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

private void checkinButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkinButtonActionPerformed
// TODO add your handling code here:
    appointment.setAppointmentStatusID(2);
}//GEN-LAST:event_checkinButtonActionPerformed

private void checkinCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkinCheckBoxActionPerformed
    // TODO add your handling code here:
    appointment.setAppointmentStatusID(2);
    
}//GEN-LAST:event_checkinCheckBoxActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton checkinButton;
    private javax.swing.JCheckBox checkinCheckBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel patientNameField;
    // End of variables declaration//GEN-END:variables
}
